package org.example.mapper;

import org.apache.ibatis.annotations.*;
import org.example.pojo.Newuser;
import org.example.pojo.Orders;
import org.example.pojo.User;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public interface UserMapper {
    @Select("select * from user where username=#{username} and sex=#{sex}")
    List<User> selectBycon(User user);

    @Select("select * from user where username=#{username} and sex=#{sex}")
    List<Map <String,Object>> selectBycon2(Map <String,Object> map);

    @Select("select * from user where id=#{id}")
    @Results({@Result(id = true ,column ="id" , property = "userid"),
    @Result(column="username", property = "userName"),
            @Result(column = "sex",property = "userSex"),
            @Result(column = "address", property = "userAddress")
    })
    Newuser selectById(Integer id);

    @Insert("insert into user values (null, " +
            "#{username} , #{birthday} , #{sex} , #{address})")
    @SelectKey(statement = "select last_insert_id()",before = false ,keyProperty = "id" , resultType = Integer.class)
    Integer insert (User user);



    @Select("select * from user where id=#{id}")
    User selectById2(Integer id);


    @Select("select * from user ")
    @Results({
            @Result(column = "id",property = "ordersList",
                    many = @Many(select = "org.example.mapper.OrderMapper.selectByuUserId"))
    })
    List<User> selectAll();
}
